function [s_hat,signal] = rate_34_detector_qamsixteen(h,r,rho,nt,nr)

for m=0:15
	int_rep=int2bin(m);
	s_possible(m+1)=bin2qamsixteen(int_rep(5:8));
end



sum2=0;
for k=1:nr
	for z=1:3
		sum2=sum2+ abs(h(k,z)).^2;
	end
end

sum1=0;
for k=1:nr
	sum1=sum1+ r(k,1)*conj(h(k,1)) + conj(r(k,2))*h(k,2) + .5* ( (r(k,4) - r(k,3)) *conj(h(k,3)) ) - .5*( conj(r(k,3) + r(k,4)) *(h(k,3)) ); 
end
sum1=sum1*sqrt(nt/rho);
sum=(abs(sum1-s_possible)).^2 + (-1 + sum2)*(abs(s_possible).^2);
[minim,index]=min(sum);
s_hat(1)=s_possible(index);

sum1=0;
for k=1:nr
	sum1=sum1+ r(k,1)*conj(h(k,2)) - conj(r(k,2))*h(k,1) + .5* ( (r(k,4) + r(k,3)) *conj(h(k,3)) ) - .5*( conj(-r(k,3) + r(k,4)) *(h(k,3)) ); 
end
sum1=sum1*sqrt(nt/rho);
sum=(abs(sum1-s_possible)).^2 + (-1 + sum2)*(abs(s_possible).^2);
[minim,index]=min(sum);
s_hat(2)=s_possible(index);

sum1=0;
for k=1:nr
	sum1=sum1+ (1/sqrt(2)) * ( (r(k,1) + r(k,2)) *conj(h(k,3)) );
	sum1=sum1+ (1/sqrt(2)) * conj(r(k,3)) * (h(k,1) + h(k,2)); 
	sum1=sum1+ (1/sqrt(2)) * conj(r(k,4)) * (h(k,1) - h(k,2)); 
end
sum1=sum1*sqrt(nt/rho);
sum=(abs(sum1-s_possible)).^2 + (-1 + sum2)*(abs(s_possible).^2);
[minim,index]=min(sum);
s_hat(3)=s_possible(index);


signal=[];
for m=1:length(s_hat)
	signal=horzcat(signal,qamsixteen2bin(s_hat(m)));
end
